package com.mz.ozy.mvp.presenter;

import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.mvp.model.ArticleModel;
import com.mz.ozy.mvp.view.StrategyContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class StrategyPresenter extends BasePresenterImpl<StrategyContract.View> implements StrategyContract.Presenter {

    private ArticleModel mArticleModel;

    public StrategyPresenter() {
        mArticleModel = new ArticleModel();
    }

    public void queryArticleListByType(Context context, String typename, String content, int pageNo, boolean load) {
        mArticleModel.queryArticleListByType(context, typename, content, pageNo)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView, load) {

                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.getArticleListByType(jsonObject);
                    }
                });
    }

    @Override
    public void followTheObject(Context context, int id, int type) {
        mArticleModel.followTheObject(context, id, type).
                compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {

                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.followSuccess(jsonObject);
                    }
                });
    }
}
